JBoss Community Archive (Read Only)

Arquillian

Multiple Containers

There are times when you need to involve multiple containers in the same test case, if you for instance want to test clustering. The first step you need to take is to add a group with multiple containers to your Arquillian configuration.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <group qualifier="tomcat-cluster" default="true">
        <container qualifier="container-1" default="true">
            <configuration>
                <property name="tomcatHome">target/tomcat-embedded-6-standby</property>
                <property name="workDir">work</property>
                <property name="bindHttpPort">8880</property>
                <property name="unpackArchive">true</property>
            </configuration>
        </container>
        <container qualifier="container-2">
            <configuration>
                <property name="tomcatHome">target/tomcat-embedded-6-active-1</property>
                <property name="workDir">work</property>
                <property name="bindHttpPort">8881</property>
                <property name="unpackArchive">true</property>
            </configuration>
        </container>
    </group>
</arquillian>

So what we have done here is to say we have two containers that Arquillian will control, container-1 and container-2. Arquillian will now instead of starting up one container, which is normal, start up two. In your test class you can target different deployments against the different containers using the @TargetsContainer("containerName") annotation on your Deployment methods.

@Deployment(name = "dep1") @TargetsContainer("container-1")
public static WebArchive createDep1() {}

@Deployment(name = "dep2")  @TargetsContainer("container-2")
public static WebArchive createDep2() {}

@Test @OperateOnDeployment("dep1")
public void testRunningInDep1() {}

@Test @OperateOnDeployment("dep2")
public void testRunningInDep2() {}

We now have a single test class that will be executed in two different containers. testRunningInDep1 will operate in the context of the dep1 deployment which is deployed on the container named container-1 and testRunningInDep2 will operate in the context of deployment dep2 which is deployed on container container-2. As the test moves along, each method is executed inside the individual containers.

Arquillian does not support ClassLoader isolation on the client side so for this feature to work the container adapter must support running multiple instances within the same ClassLoader/JVM. Currently this only works with containers of type Remote or Managed as the adapter normally will connect to an isolated server started in its own JVM.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 09:40:17 UTC, last content change 2014-02-24 08:39:53 UTC.